<template>
	<view class="groupData">
		<!-- 		<view class="groupDataTitle">
			<span class='item'>拼友：<span>{{memberCount}}人</span></span>
		</view> -->
		<view class="list">
			<view class='item' v-for='(item,index) in list' :key='index'>
				<view class="left">
					<p>日期：{{item.createTime}}至{{ item.endTime }} </p>
				</view>
				<view class="right">
					<p>成团数量：{{item.groupSuccessCount}} </p>
				</view>

			</view>

		</view>
	</view>


	</view>
</template>

<script>
	import API from '@/common/api';
	import utils from '@/common/utils';
	import uniLoadMore from '@/components/uni-load-more.vue';
	export default {
		data() {
			return {
				total: 0,
				todayCount: 0,
				memberCount: 0,
				loading: false,
				finished: false,
				params: {
					limit: 10,
					page: 0,
				},
				loadMoreText: '加载中...',
				loadingText: {
					contentdown: '上拉显示更多',
					contentrefresh: '正在加载...',
					contentnomore: '没有更多数据了'
				},
				showLoadMore: false,
				list: [],
			}
		},
		onLoad() {
			this.getList()
		},
		components: {
			uniLoadMore
		},
		onPullDownRefresh() {
			this.page = 0;
			this.getList();
			this.finished = false;
		},
		onUnload() {
			this.showLoadMore = false;
		},
		onReachBottom() {
			console.log(this.finished, 'onReachBottom  finished');
			if (!this.finished) {
				this.showLoadMore = true;
				setTimeout(() => {
					this.page++;
					this.getList();
				}, 300);
			}
		},
		methods: {
			async getList() {
				uni.showLoading({
					title: '正在加载...'
				});
				this.loading = true;
				API.weekDataList(this.params).then(res => {
					if (res.code == 200) {
						let json = res;
						uni.hideLoading();
						if (0 == this.params.page) {
							this.list = []
						}
						for (let i = 0; i < json.data.length; i++) {
							this.list.push({
								createTime: utils.timestampToFormatString(json.data[i].createTime, "yyyy-MM-dd"),
								endTime: utils.timestampToFormatString(json.data[i].createTime+7*24*3600*1000-1, "yyyy-MM-dd"),
								groupSuccessCount: json.data[i].groupSuccessCount,
							});
						}

						uni.stopPullDownRefresh();
						// 加载状态结束
						this.loading = false;
						if (json.data.length < this.params.limit) {
							this.finished = true;
							this.showLoadMore = false;
						}
						this.total = json.total
					}
				});
			},
		}
	}
</script>

<style lang="less">
	.groupData {
		background: white;

		.groupDataTitle {
			padding: 1rem;
			border-bottom: 1px solid #ececec;
			display: flex;
			justify-content: space-between;
		}

		.list {
			.item {
				display: flex;
				justify-content: space-between;
				padding: 1rem;
				border-bottom: 1px solid rgba(236, 236, 236, 1);
				.left {}
				.right {
					display: flex;
					flex-direction: column;
					justify-content: flex-end;
				}
			}
		}
	}
</style>
